package com.page2;

public class TestPage266 {

	public static void main(String[] args) {
		int a[] = {2,3,8,9};
		int b[] = {2,3,9,7};
		System.out.println(resolve(a,b));
	}
	
	public static int resolve(int a[],int b[]){
		int n = a.length;
		int m = b.length;
		
		int dp[][] = new int[n+1][m+1];
		
		for(int i = 1;i<n;i++){
			for(int j = 1;j<m;j++){
				if(a[i] == b[j]){
					for(int k = 1;k<j;k++){
						if(b[k]<b[j])
						dp[i][j] = Math.max(dp[i][j], dp[i-1][k]+1);
					}
				}else{
					dp[i][j] = dp[i-1][j];
				}
			}
		}
		
		
		return dp[n-1][m-1];
	}
	
	
}
